<?php

namespace app\common\model\other;
use think\Model;
use fast\Tree;
class Study extends Model
{


    public function getCreatetimeAttr($value)
    {
        $status = date('Y-m-d', $value);
        return $status;
    }


    /**
     * 读取分类列表
     * @param string $type   指定类型
     * @param string $status 指定状态
     * @return array
     */
    public static function getList()
    {

        $list=self::where(function ($query)  {
            $query->where('status', '=', 'normal');
            $query->where('is_home_show', '=', 1);
        })->order(['weigh'=>'desc','createtime'=>'desc'])->field('id,title,createtime,image')->select();
        return $list;
    }




    /**
     * 读取分类列表
     * @param string $type   指定类型
     * @param string $status 指定状态
     * @return array
     */
    //根据分类ID获取指定数据
    public static function getPageList($data)
    {
        $info=self::where(function ($query)  {
            $query->where('status', '=', 'normal');
        })->order('weigh', 'desc');
        if(!empty($data['category_id'])){
            $info->where('category_id',$data['category_id']);
        }
        if(!empty($data['keywords'])){
            $info->where('title','like','%'.$data['keywords'].'%');
        }
        $list=$info->field('id,title,createtime,image,category_id')->order(['weigh'=>'desc','createtime'=>'desc'])->paginate(15,false,['page'=>$data['page']]);
        return $list;
    }

    /*
      * 读取分页
      * @param string $type   指定类型
      * @param string $status 指定状态
      * @return array
      */
    public static function details($id)
    {

        $list=self::where(['id'=>$id,'status'=>'normal'])->find();
        $list->setInc('show_number',1);
        return $list;
    }

}
